package com.yzy.fly.mapper;

import com.yzy.fly.entity.role.FlyProcess;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface FlyProcessMapper extends FlyBasicMapper<FlyProcess> {
    @Select("select * from fly_process a where a.id = #{id}")
    FlyProcess selectById(@Param("id") int id);

    @Select("select * from fly_process a where 1=1")
    List<FlyProcess> selectAll();

    @Select("select * from fly_process a where 1=1 and a.componentId = #{componentId} order by a.seq asc")
    List<FlyProcess> selectAllByClassId(@Param("componentId") int componentId);

    @Select("select * from fly_process a where 1=1 and a.systemId = #{systemId}")
    List<FlyProcess> selectAllBySystemId(@Param("systemId") int systemId);

//    @Select({"select * from fly_process a where 1=1 and a.classId = (select b.fieldId from fly_field_annotation b where b.id = #{annotationId})",
//    "","",""})
    @Select({"<script>",
            "select * ",
            "from fly_process a",
            "where 1=1",
            "<when test='componentId!=null'>",
            "AND a.componentId = #{componentId}",
            "</when>",
            "<when test='systemId!=null'>",
            "AND a.systemId = #{systemId}",
            "</when>",
            "</script>"})
    List<FlyProcess> selectAllByParentId(@Param("componentId") Integer componentId, @Param("systemId") Integer systemId);

    @Select("select * from fly_process a where 1=1 and a.name = #{name}")
    FlyProcess selectOneByName(@Param("name") String name);

}